package com.hns.can.energy.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.DriverInterfaceAnnotation;
import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.energy.vo.NewEnergy;
import com.hns.can.master.entity.CommEnerConsStatInfoEntity;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 驾驶员里程service
 * @author:zhangy
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Service
public class DrivingMileageService extends CommonService { 
	
	@Autowired
    private FillCodeDscValue codeDscValue;

	/**
	 * 查询驾驶员里程报表
	 * @param vo
	 * @return
	 * @throws Exception
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@LeftOrgAnnotation()
    @Transactional
    @DriverInterfaceAnnotation()
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Pagination searchDrivingMileage(NewEnergy vo) throws Exception {
		Pagination page = this.myBatisPage("drivingMileage.searchDrivingMileageCnt", 
				"drivingMileage.searchDrivingMileageData", vo, CommEnerConsStatInfoEntity.class);
		List list = page.getData();
		fillDrivingEnergy(list);
		page.setData(list);
		return page;
	}
	
	/**
	 * 查询导出驾驶员里程数据
	 * @param vo
	 * @return
	 * @throws Exception
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@LeftOrgAnnotation()
    @Transactional
    @DriverInterfaceAnnotation()
	@SuppressWarnings("rawtypes")
	public List getDrivingMileage(NewEnergy vo) throws Exception {
		List list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("drivingMileage.searchDrivingMileageData", vo), CommEnerConsStatInfoEntity.class);
		fillDrivingEnergy(list);
		return list;
	}

	/**
	 * 填充字段值
	 * @param list
	 * @throws Exception
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings("rawtypes")
	private void fillDrivingEnergy(List list) throws Exception {
        //转化生成线路名称
        Map<String,String> map = new HashMap<String,String>();
        map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo fileVo1 = new FillParamsVo("lineId", map);
        
        //转化生成机构名称
        map = new HashMap<String,String>();
        map.put("organName",  GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo fileVo2 = new FillParamsVo("organId", map);
        
        //转化生成车牌号、车辆类别、车辆、燃料类型
        map= new HashMap<String,String>();
        map.put("licPltNo",  GlobalConst.DEFAULT_CACHE_VALUE);
        map.put("carType", "carType");
        map.put("engiNo", "engiNo");
        
        //转化生成驾驶员名称
        FillParamsVo fileVo3 = new FillParamsVo("carId", map);
        map = new HashMap<String,String>();
        map.put("drvName",  GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo fileVo4 = new FillParamsVo("drvId", map);
        
        codeDscValue.fillInfoValue(list,new String[] {GlobalConst.CACHE_KEY_BASE_LINE_INFO, 
            GlobalConst.CACHE_KEY_BASE_DRV_INFO, GlobalConst.CACHE_KEY_BASE_ORGAN, 
            GlobalConst.CACHE_KEY_BASE_CAR_INFO}, fileVo1, fileVo2, fileVo3, fileVo4);
        Map<String, String> mapTmp = new HashMap<String, String>();
        mapTmp.put("carType", "CAT00000");
        codeDscValue.fillCodeDscValue(list, mapTmp);
    }
	
}
